#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    int numberOfSubarrays(vector<int>& nums, int k) {
        int ans = 0;
        deque<int> store;
        store.push_back(-1);
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] % 2 == 1) {
                store.push_back(i);
                if (store.size() == k + 2) {
                    int back1 = store.back();
                    store.pop_back();
                    int back2 = store.back();
                    int sub2 = back1 - back2;
                    int front1 = store.front();
                    store.pop_front();
                    int front2 = store.front();
                    int sub1 = front2 - front1;
                    ans += sub2 * sub1;
                    store.push_back(back1);
                }
            }
        }
        store.push_back(nums.size());
        if (store.size() == k + 2) {
            int back1 = store.back();
            store.pop_back();
            int back2 = store.back();
            int sub2 = back1 - back2;
            int front1 = store.front();
            store.pop_front();
            int front2 = store.front();
            int sub1 = front2 - front1;
            ans += sub2 * sub1;
        }
        return ans;
    }
};

int main() {
    vector<int> input = vector<int>{1, 1, 2, 1, 1};
    Solution solution;
    solution.numberOfSubarrays(input, 3);
    return 0;
}
